<!DOCTYPE html><html lang="zh-CN"><head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1"><meta name="format-detection" content="telephone=no"><meta name="apple-mobile-web-app-capable" content="yes"><meta name="apple-mobile-web-app-status-bar-style" content="black"><link rel="icon" href="/images/icons/IMG_1680(20230123-175413).JPG?v=2.8.0" type="image/png" sizes="16x16"><link rel="icon" href="/images/icons/IMG_1680(20230123-175413).JPG?v=2.8.0" type="image/png" sizes="32x32"><meta name="description" content="AOP底层实现原理：                           首先定义一个接口Vehicle       1234567891011public class Car implements Vehicle&amp;#123;    @Override    public void run() &amp;#123;        System.out.println">
<meta property="og:type" content="article">
<meta property="og:title" content="Spring笔记">
<meta property="og:url" content="http://shuaidaia.gitee.io/2024/03/14/Spring%E7%AC%94%E8%AE%B0/index.html">
<meta property="og:site_name" content="码农呆的奋斗史">
<meta property="og:description" content="AOP底层实现原理：                           首先定义一个接口Vehicle       1234567891011public class Car implements Vehicle&amp;#123;    @Override    public void run() &amp;#123;        System.out.println">
<meta property="og:locale" content="zh_CN">
<meta property="article:published_time" content="2024-03-14T06:53:13.000Z">
<meta property="article:modified_time" content="2024-03-14T07:16:39.319Z">
<meta property="article:author" content="Belly	|	vx：lin128Ve98">
<meta property="article:tag" content="Spirng">
<meta name="twitter:card" content="summary"><title>Spring笔记 | 码农呆的奋斗史</title><link ref="canonical" href="http://shuaidaia.gitee.io/2024/03/14/Spring%E7%AC%94%E8%AE%B0/"><link rel="dns-prefetch" href="https://cdn.jsdelivr.net"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free@5.12.1/css/all.min.css" type="text/css"><link rel="stylesheet" href="/css/index.css?v=2.8.0"><link rel="stylesheet" href="css/custom.css"><script>var Stun = window.Stun || {};
var CONFIG = {
  root: '/',
  algolia: undefined,
  assistSearch: undefined,
  fontIcon: {"prompt":{"success":"fas fa-check-circle","info":"fas fa-arrow-circle-right","warning":"fas fa-exclamation-circle","error":"fas fa-times-circle"},"copyBtn":"fas fa-copy"},
  sidebar: {"offsetTop":"20px","tocMaxDepth":6},
  header: {"enable":true,"showOnPost":true,"scrollDownIcon":false},
  postWidget: {"endText":true},
  nightMode: {"enable":true},
  back2top: {"enable":true},
  codeblock: {"style":"default","highlight":"light","wordWrap":false},
  reward: false,
  fancybox: false,
  zoomImage: {"gapAside":"20px"},
  galleryWaterfall: undefined,
  lazyload: false,
  pjax: undefined,
  externalLink: {"icon":{"enable":true,"name":"fas fa-external-link-alt"}},
  shortcuts: undefined,
  prompt: {"copyButton":"复制","copySuccess":"复制成功","copyError":"复制失败"},
  sourcePath: {"js":"js","css":"css","images":"images"},
};

window.CONFIG = CONFIG;</script><meta name="generator" content="Hexo 6.3.0"></head><body><div class="container" id="container"><header class="header" id="header"><div class="header-inner"><nav class="header-nav header-nav--fixed"><div class="header-nav-inner"><div class="header-nav-menubtn"><i class="fas fa-bars"></i></div><div class="header-nav-menu"><div class="header-nav-menu-item"><a class="header-nav-menu-item__link" href="/"><span class="header-nav-menu-item__icon"><i class="fas fa-home"></i></span><span class="header-nav-menu-item__text">首页</span></a></div><div class="header-nav-menu-item"><a class="header-nav-menu-item__link" href="/archives/"><span class="header-nav-menu-item__icon"><i class="fas fa-folder-open"></i></span><span class="header-nav-menu-item__text">归档</span></a></div><div class="header-nav-menu-item"><a class="header-nav-menu-item__link" href="/categories/"><span class="header-nav-menu-item__icon"><i class="fas fa-layer-group"></i></span><span class="header-nav-menu-item__text">分类</span></a></div><div class="header-nav-menu-item"><a class="header-nav-menu-item__link" href="/tags/"><span class="header-nav-menu-item__icon"><i class="fas fa-tags"></i></span><span class="header-nav-menu-item__text">标签</span></a></div></div><div class="header-nav-mode"><div class="mode"><div class="mode-track"><span class="mode-track-moon"></span><span class="mode-track-sun"></span></div><div class="mode-thumb"></div></div></div></div></nav><div class="header-banner"><div class="header-banner-info"><div class="header-banner-info__subtitle">总有人间一两风，填我十万八千梦。</div></div></div></div></header><main class="main" id="main"><div class="main-inner"><div class="content-wrap" id="content-wrap"><div class="content" id="content"><!-- Just used to judge whether it is an article page--><div id="is-post"></div><div class="post"><header class="post-header"><h1 class="post-title">Spring笔记</h1><div class="post-meta"><span class="post-meta-item post-meta-item--createtime"><span class="post-meta-item__icon"><i class="far fa-calendar-plus"></i></span><span class="post-meta-item__info">发表于</span><span class="post-meta-item__value">2024-03-14</span></span><span class="post-meta-item post-meta-item--updatetime"><span class="post-meta-item__icon"><i class="far fa-calendar-check"></i></span><span class="post-meta-item__info">更新于</span><span class="post-meta-item__value">2024-03-14</span></span></div></header><div class="post-body">
        <h2 id="AOP底层实现原理："   >
          <a href="#AOP底层实现原理：" class="heading-link"><i class="fas fa-link"></i></a><a href="#AOP底层实现原理：" class="headerlink" title="AOP底层实现原理："></a>AOP底层实现原理：</h2>
      
        <h5 id="首先定义一个接口Vehicle"   >
          <a href="#首先定义一个接口Vehicle" class="heading-link"><i class="fas fa-link"></i></a><a href="#首先定义一个接口Vehicle" class="headerlink" title="首先定义一个接口Vehicle"></a>首先定义一个接口Vehicle</h5>
      <figure class="highlight java"><div class="table-container"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">public</span> <span class="keyword">class</span> <span class="title class_">Car</span> <span class="keyword">implements</span> <span class="title class_">Vehicle</span>&#123;</span><br><span class="line">    <span class="meta">@Override</span></span><br><span class="line">    <span class="keyword">public</span> <span class="keyword">void</span> <span class="title function_">run</span><span class="params">()</span> &#123;</span><br><span class="line">        System.out.println(<span class="string">&quot;Car正在run~~~&quot;</span>);</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="meta">@Override</span></span><br><span class="line">    <span class="keyword">public</span> String <span class="title function_">fly</span><span class="params">(<span class="type">int</span> height)</span> &#123;</span><br><span class="line">        <span class="keyword">return</span> <span class="string">&quot;Car飞行的高度为：&quot;</span> + height;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></div></figure>


        <h5 id="然后定义两个Car和Ship类去实现Vehicle接口"   >
          <a href="#然后定义两个Car和Ship类去实现Vehicle接口" class="heading-link"><i class="fas fa-link"></i></a><a href="#然后定义两个Car和Ship类去实现Vehicle接口" class="headerlink" title="然后定义两个Car和Ship类去实现Vehicle接口"></a>然后定义两个Car和Ship类去实现Vehicle接口</h5>
      <figure class="highlight java"><div class="table-container"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">public</span> <span class="keyword">class</span> <span class="title class_">Car</span> <span class="keyword">implements</span> <span class="title class_">Vehicle</span>&#123;</span><br><span class="line">    <span class="meta">@Override</span></span><br><span class="line">    <span class="keyword">public</span> <span class="keyword">void</span> <span class="title function_">run</span><span class="params">()</span> &#123;</span><br><span class="line">        System.out.println(<span class="string">&quot;Car正在run~~~&quot;</span>);</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="meta">@Override</span></span><br><span class="line">    <span class="keyword">public</span> String <span class="title function_">fly</span><span class="params">(<span class="type">int</span> height)</span> &#123;</span><br><span class="line">        <span class="keyword">return</span> <span class="string">&quot;Car飞行的高度为：&quot;</span> + height;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></div></figure>

<figure class="highlight java"><div class="table-container"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">public</span> <span class="keyword">class</span> <span class="title class_">Ship</span> <span class="keyword">implements</span> <span class="title class_">Vehicle</span>&#123;</span><br><span class="line">    <span class="meta">@Override</span></span><br><span class="line">    <span class="keyword">public</span> <span class="keyword">void</span> <span class="title function_">run</span><span class="params">()</span> &#123;</span><br><span class="line">        System.out.println(<span class="string">&quot;Ship正在run~~~&quot;</span>);</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="meta">@Override</span></span><br><span class="line">    <span class="keyword">public</span> String <span class="title function_">fly</span><span class="params">(<span class="type">int</span> height)</span> &#123;</span><br><span class="line">        <span class="keyword">return</span> <span class="string">&quot;Ship飞行的高度为：&quot;</span> + height;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></div></figure>


        <h5 id="最后定义VehicleProxyProvider返回一个代理对象"   >
          <a href="#最后定义VehicleProxyProvider返回一个代理对象" class="heading-link"><i class="fas fa-link"></i></a><a href="#最后定义VehicleProxyProvider返回一个代理对象" class="headerlink" title="最后定义VehicleProxyProvider返回一个代理对象"></a>最后定义VehicleProxyProvider返回一个代理对象</h5>
      <figure class="highlight java"><div class="table-container"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">public</span> <span class="keyword">class</span> <span class="title class_">VehicleProxyProvider</span> &#123;</span><br><span class="line">    <span class="comment">//定义一个属性</span></span><br><span class="line">    <span class="comment">//target_vehicle表示真正执行的对象</span></span><br><span class="line">    <span class="comment">//该对象需要实现了Vehicle接口</span></span><br><span class="line">    <span class="keyword">private</span> Vehicle target_vehicle;</span><br><span class="line"></span><br><span class="line">    <span class="keyword">public</span> <span class="title function_">VehicleProxyProvider</span><span class="params">(Vehicle target_vehicle)</span> &#123;</span><br><span class="line">        <span class="built_in">this</span>.target_vehicle = target_vehicle;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="comment">//编写一个可以返回代理对象的方法，</span></span><br><span class="line">    <span class="comment">// 该代理对象可以通过反射机制调用到被代理对象的方法</span></span><br><span class="line">    <span class="keyword">public</span> Vehicle <span class="title function_">getProxy</span><span class="params">()</span>&#123;</span><br><span class="line"></span><br><span class="line">        <span class="comment">//得到类的加载器</span></span><br><span class="line">        <span class="type">ClassLoader</span> <span class="variable">classLoader</span> <span class="operator">=</span></span><br><span class="line">                target_vehicle.getClass().getClassLoader();</span><br><span class="line"></span><br><span class="line">        <span class="comment">//得到要代理的对象/被执行对象的接口信息，底层是通过接口来完成调用</span></span><br><span class="line">        Class&lt;?&gt;[] interfaces =</span><br><span class="line">                target_vehicle.getClass().getInterfaces();</span><br><span class="line"></span><br><span class="line">        <span class="comment">//创建InvocationHandler对象</span></span><br><span class="line">        <span class="comment">//因为InvocationHandler是接口，</span></span><br><span class="line">        <span class="comment">// 所有我们可以通过局部内部类的方式来创建该对象</span></span><br><span class="line">        <span class="comment">/**</span></span><br><span class="line"><span class="comment">         * public interface InvocationHandler &#123;</span></span><br><span class="line"><span class="comment">         *      public Object invoke(Object proxy, Method method, Object[] args)</span></span><br><span class="line"><span class="comment">         *      throws Throwable;</span></span><br><span class="line"><span class="comment">         *      &#125;</span></span><br><span class="line"><span class="comment">         *   invoke方法是将来执行我们的target_vehicle的方法时，会调用到</span></span><br><span class="line"><span class="comment">         */</span></span><br><span class="line">        <span class="type">InvocationHandler</span> <span class="variable">invocationHandler</span> <span class="operator">=</span></span><br><span class="line">                <span class="keyword">new</span> <span class="title class_">InvocationHandler</span>() &#123;</span><br><span class="line">                    <span class="comment">/**</span></span><br><span class="line"><span class="comment">                     * invoke方法是将来执行我们的target_vehicle的方法时，会调用</span></span><br><span class="line"><span class="comment">                     *</span></span><br><span class="line"><span class="comment">                     * <span class="doctag">@param</span> proxy 表示代理对象</span></span><br><span class="line"><span class="comment">                     *</span></span><br><span class="line"><span class="comment">                     * <span class="doctag">@param</span> method 就是通过代理对象调用方法时去掉的那个方法，</span></span><br><span class="line"><span class="comment">                     *               如：代理对象.run() 或者 代理对象.fly(100)</span></span><br><span class="line"><span class="comment">                     *</span></span><br><span class="line"><span class="comment">                     * <span class="doctag">@param</span> args 表示调用代理对象来执行方法时需要传入的参数，</span></span><br><span class="line"><span class="comment">                     *             如：代理对象.fly(xxx) xxx就是传入的参数</span></span><br><span class="line"><span class="comment">                     *</span></span><br><span class="line"><span class="comment">                     * <span class="doctag">@return</span> 表示代理对象.run()执行后的结果</span></span><br><span class="line"><span class="comment">                     * <span class="doctag">@throws</span> Throwable</span></span><br><span class="line"><span class="comment">                     */</span></span><br><span class="line">            <span class="meta">@Override</span></span><br><span class="line">            <span class="keyword">public</span> Object <span class="title function_">invoke</span><span class="params">(Object proxy, Method method, Object[] args)</span> <span class="keyword">throws</span> Throwable &#123;</span><br><span class="line">                System.out.println(<span class="string">&quot;全部开始运作咯~~~&quot;</span>);</span><br><span class="line">                <span class="comment">//这里method 是public abstract void com.belly.spring.proxy1.Vehicle.run()</span></span><br><span class="line">                <span class="comment">//          或是public abstract void com.belly.spring.proxy1.Vehicle.fly(xxx)</span></span><br><span class="line">                <span class="comment">//target_vehicle 是需要代理的对象</span></span><br><span class="line">                <span class="comment">//args 是代理对象调用的方法里的参数，如：fly(xxx)方法参数为xxx、</span></span><br><span class="line">                <span class="comment">//                              run()方法没有参数所有args为null</span></span><br><span class="line">                <span class="type">Object</span> <span class="variable">result</span> <span class="operator">=</span> method.invoke(target_vehicle, args);</span><br><span class="line">                System.out.println(<span class="string">&quot;全部停止运作咯~~~&quot;</span>);</span><br><span class="line">                <span class="keyword">return</span> result;</span><br><span class="line">            &#125;</span><br><span class="line">        &#125;;</span><br><span class="line"></span><br><span class="line">        <span class="comment">/**</span></span><br><span class="line"><span class="comment">         * public static Object newProxyInstance(ClassLoader loader,</span></span><br><span class="line"><span class="comment">         *                                           Class&lt;?&gt;[] interfaces,</span></span><br><span class="line"><span class="comment">         *                                           InvocationHandler h)</span></span><br><span class="line"><span class="comment">         *   newProxyInstance()方法说明:</span></span><br><span class="line"><span class="comment">         *   1.newProxyInstance()方法可以返回一个代理对象</span></span><br><span class="line"><span class="comment">         *   2.ClassLoader loader 类的加载器</span></span><br><span class="line"><span class="comment">         *   3.Class&lt;?&gt;[] interfaces 就是将来要代理的对象的接口信息</span></span><br><span class="line"><span class="comment">         *   4.InvocationHandler h 调用处理器/对象 其中它里面有一个非常重要的方法invoke</span></span><br><span class="line"><span class="comment">         */</span></span><br><span class="line">        <span class="type">Vehicle</span> <span class="variable">proxy</span> <span class="operator">=</span></span><br><span class="line">                (Vehicle) Proxy.newProxyInstance(classLoader, interfaces, invocationHandler);</span><br><span class="line"></span><br><span class="line">        <span class="keyword">return</span> proxy;</span><br><span class="line">    &#125;</span><br></pre></td></tr></table></div></figure>

<p>这样我们就能够通过给VehicleProxyProvider传入一个Car对象或则Ship对象来返回一个代理对象，AOP就是在反射调用目标方法的前后去执行你所定义的代码，如图：</p>
<figure class="highlight java"><div class="table-container"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">@Override</span></span><br><span class="line">            <span class="keyword">public</span> Object <span class="title function_">invoke</span><span class="params">(Object proxy, Method method, Object[] args)</span> <span class="keyword">throws</span> Throwable &#123;</span><br><span class="line">                <span class="type">Object</span> <span class="variable">result</span> <span class="operator">=</span> <span class="literal">null</span>;</span><br><span class="line">                <span class="keyword">try</span> &#123;</span><br><span class="line"></span><br><span class="line">                    System.out.println(<span class="string">&quot;方法执行前-日志-方法名-&quot;</span> + method.getName() + <span class="string">&quot;-参数&quot;</span></span><br><span class="line">                            + Arrays.asList(args));<span class="comment">//这里从AOP角度看，就是一个横切关注点-前置通知</span></span><br><span class="line">                    BellyAOP.before(proxy, method, args);</span><br><span class="line"></span><br><span class="line">                    <span class="comment">//使用反射调用方法</span></span><br><span class="line">                    result = method.invoke(target_obj, args);</span><br><span class="line"></span><br><span class="line">                    System.out.println(<span class="string">&quot;方法执行正常结束-日志-方法名-&quot;</span> + method.getName()</span><br><span class="line">                            + <span class="string">&quot;-结果result=&quot;</span> + result);<span class="comment">//从AOP角度看，这也是横切关注点-返回通知</span></span><br><span class="line"></span><br><span class="line">                &#125; <span class="keyword">catch</span> (Exception e) &#123;</span><br><span class="line"></span><br><span class="line">                    System.out.println(<span class="string">&quot;方法执行异常-日志-方法名-&quot;</span> + method.getName()</span><br><span class="line">                            + <span class="string">&quot;-异常类型=&quot;</span> + e.getClass().getName());<span class="comment">//从AOP角度看，也是横切关注点-异常通知</span></span><br><span class="line">                    <span class="keyword">throw</span> <span class="keyword">new</span> <span class="title class_">RuntimeException</span>(e);</span><br><span class="line"></span><br><span class="line">                &#125; <span class="keyword">finally</span> &#123;</span><br><span class="line"></span><br><span class="line">                    <span class="comment">//从AOP的角度看，也是一个横切关注点-最终通知</span></span><br><span class="line">                    System.out.println(<span class="string">&quot;方法最终结束-日志-方法名-&quot;</span> + method.getName());</span><br><span class="line"></span><br><span class="line">                &#125;</span><br><span class="line">                <span class="keyword">return</span> result;</span><br><span class="line">            &#125;</span><br></pre></td></tr></table></div></figure>
</div><footer class="post-footer"><div class="post-ending ending"><div class="ending__text">------ 本文结束，感谢您的阅读 ------</div></div><div class="post-copyright copyright"><div class="copyright-author"><span class="copyright-author__name">本文作者: </span><span class="copyright-author__value"><a href="http://shuaidaia.gitee.io">Belly	|	vx：lin128Ve98</a></span></div><div class="copyright-link"><span class="copyright-link__name">本文链接: </span><span class="copyright-link__value"><a href="http://shuaidaia.gitee.io/2024/03/14/Spring%E7%AC%94%E8%AE%B0/">http://shuaidaia.gitee.io/2024/03/14/Spring%E7%AC%94%E8%AE%B0/</a></span></div><div class="copyright-notice"><span class="copyright-notice__name">版权声明: </span><span class="copyright-notice__value">本博客所有文章除特别声明外，均采用 <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/deed.en" rel="external nofollow" target="_blank">BY-NC-SA</a> 许可协议。转载请注明出处！</span></div></div><div class="post-tags"><span class="post-tags-item"><span class="post-tags-item__icon"><i class="fas fa-tag"></i></span><a class="post-tags-item__link" href="http://shuaidaia.gitee.io/tags/Spirng/">Spirng</a></span></div><nav class="post-paginator paginator"><div class="paginator-prev"><a class="paginator-prev__link" href="/2024/04/03/HTTP%E5%93%8D%E5%BA%94%E7%8A%B6%E6%80%81%E7%A0%81/"><span class="paginator-prev__icon"><i class="fas fa-angle-left"></i></span><span class="paginator-prev__text">HTTP响应状态码大全及介绍</span></a></div><div class="paginator-next"><a class="paginator-next__link" href="/2024/03/14/SpringMVC%E7%AC%94%E8%AE%B0/"><span class="paginator-prev__text">SpringMVC笔记</span><span class="paginator-next__icon"><i class="fas fa-angle-right"></i></span></a></div></nav></footer></div></div></div><div class="sidebar-wrap" id="sidebar-wrap"><aside class="sidebar" id="sidebar"><div class="sidebar-nav"><span class="sidebar-nav-toc current">文章目录</span><span class="sidebar-nav-ov">站点概览</span></div><section class="sidebar-toc"><ol class="toc"><li class="toc-item toc-level-2"><a class="toc-link" href="#AOP%E5%BA%95%E5%B1%82%E5%AE%9E%E7%8E%B0%E5%8E%9F%E7%90%86%EF%BC%9A"><span class="toc-number">1.</span> <span class="toc-text">
          AOP底层实现原理：</span></a><ol class="toc-child"><li class="toc-item toc-level-5"><a class="toc-link" href="#%E9%A6%96%E5%85%88%E5%AE%9A%E4%B9%89%E4%B8%80%E4%B8%AA%E6%8E%A5%E5%8F%A3Vehicle"><span class="toc-number">1.0.0.1.</span> <span class="toc-text">
          首先定义一个接口Vehicle</span></a></li><li class="toc-item toc-level-5"><a class="toc-link" href="#%E7%84%B6%E5%90%8E%E5%AE%9A%E4%B9%89%E4%B8%A4%E4%B8%AACar%E5%92%8CShip%E7%B1%BB%E5%8E%BB%E5%AE%9E%E7%8E%B0Vehicle%E6%8E%A5%E5%8F%A3"><span class="toc-number">1.0.0.2.</span> <span class="toc-text">
          然后定义两个Car和Ship类去实现Vehicle接口</span></a></li><li class="toc-item toc-level-5"><a class="toc-link" href="#%E6%9C%80%E5%90%8E%E5%AE%9A%E4%B9%89VehicleProxyProvider%E8%BF%94%E5%9B%9E%E4%B8%80%E4%B8%AA%E4%BB%A3%E7%90%86%E5%AF%B9%E8%B1%A1"><span class="toc-number">1.0.0.3.</span> <span class="toc-text">
          最后定义VehicleProxyProvider返回一个代理对象</span></a></li></ol></li></ol></li></ol></li></ol></section><!-- ov = overview--><section class="sidebar-ov hide"><div class="sidebar-ov-author"><div class="sidebar-ov-author__avatar"><img class="sidebar-ov-author__avatar_img" src="/pho/IMG_0744(20220413-103811).JPG" alt="avatar"></div><p class="sidebar-ov-author__text">时时勤拂拭，勿使惹尘埃。</p></div><div class="sidebar-ov-state"><a class="sidebar-ov-state-item sidebar-ov-state-item--posts" href="/archives/"><div class="sidebar-ov-state-item__count">19</div><div class="sidebar-ov-state-item__name">归档</div></a><a class="sidebar-ov-state-item sidebar-ov-state-item--categories" href="/categories/"><div class="sidebar-ov-state-item__count">5</div><div class="sidebar-ov-state-item__name">分类</div></a><a class="sidebar-ov-state-item sidebar-ov-state-item--tags" href="/tags/"><div class="sidebar-ov-state-item__count">17</div><div class="sidebar-ov-state-item__name">标签</div></a></div><div class="sidebar-ov-cc"><a href="https://creativecommons.org/licenses/by-nc-sa/4.0/deed.en" target="_blank" rel="noopener" data-popover="知识共享许可协议" data-popover-pos="up"><img src="/images/cc-by-nc-sa.svg"></a></div></section><div class="sidebar-reading"><div class="sidebar-reading-info"><span class="sidebar-reading-info__text">你已阅读了 </span><span class="sidebar-reading-info__num">0</span><span class="sidebar-reading-info__perc">%</span></div><div class="sidebar-reading-line"></div></div></aside></div><div class="clearfix"></div></div></main><footer class="footer" id="footer"><div class="footer-inner"><div><span>Copyright © 2024</span><span class="footer__icon"><i class="fas fa-heart"></i></span><span>Belly	|	vx：lin128Ve98</span></div></div></footer><div class="loading-bar" id="loading-bar"><div class="loading-bar__progress"></div></div><div class="back2top" id="back2top"><span class="back2top__icon"><i class="fas fa-rocket"></i></span></div></div><script src="https://cdn.jsdelivr.net/npm/jquery@v3.4.1/dist/jquery.min.js"></script><script src="https://cdn.jsdelivr.net/npm/velocity-animate@1.5.2/velocity.min.js"></script><script src="https://cdn.jsdelivr.net/npm/velocity-animate@1.5.2/velocity.ui.min.js"></script><script src="/js/utils.js?v=2.8.0"></script><script src="/js/stun-boot.js?v=2.8.0"></script><script src="/js/scroll.js?v=2.8.0"></script><script src="/js/header.js?v=2.8.0"></script><script src="/js/sidebar.js?v=2.8.0"></script></body></html>